class ListPanelManager

  def initialize
    
    statusColumn = Gtk::TreeViewColumn.new "Status",Gtk::CellRendererText.new,:text => 0
    taskNameColumn = Gtk::TreeViewColumn.new "Task Name",Gtk::CellRendererText.new,:text => 1
    startTimeColumn = Gtk::TreeViewColumn.new "Start Time",Gtk::CellRendererText.new,:text => 2
    deadlineColumn = Gtk::TreeViewColumn.new "Deadline",Gtk::CellRendererText.new,:text => 3
    idColumn = Gtk::TreeViewColumn.new "Id",Gtk::CellRendererText.new,:text => 4
    idColumn.visible = false
    
    @listStore = Gtk::ListStore.new String,String,String,String,String
    @treeView = Gtk::TreeView.new @listStore
    @treeView.append_column statusColumn
    @treeView.append_column taskNameColumn
    @treeView.append_column startTimeColumn
    @treeView.append_column deadlineColumn
    @treeView.append_column idColumn
    @treeView.selection.set_mode Gtk::SELECTION_SINGLE
    
    @treeView.selection.signal_connect("changed") do
      @selectedModel = @treeView.selection.selected
    end
    
  end
  
  def getSelectedModel
    @selectedModel
  end
  
  def getSelectedTaskId
    @selectedModel[4]
  end
  
  def getListPanel
    @treeView
  end
  
  def addTask2Panel task
    iter = @listStore.append
    iter[0] = task.status
    iter[1] = task.name
    iter[2] = task.startTime
    iter[3] = task.deadline
    iter[4] = task.id
  end
  
  def addTasks2Panel tasks
    tasks.each {|task|
      addTask2Panel task
    }
  end
  
  def refreshPanel tasks
    @listStore.clear
    addTasks2Panel tasks
  end
  
  def refreshTask2Panel task
    @selectedModel[0] = task.status
    @selectedModel[1] = task.name
    @selectedModel[2] = task.startTime
    @selectedModel[3] = task.deadline
  end
  
  def removeTask
    @listStore.remove @selectedModel
  end
  
end
